$(function(){
    // 服务器地址...
    var address = 'http://yhapp.cqmjk.com/';
    var getinformationdetail = address + '/api/1/getinformationdetail';
    var collectionorcancelinformation = address + '/api/1/collectionorcancelinformation';

    //下面这封装好的函数是获取URL中参数值的方法:
    function GetQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    };

    var userId = GetQueryString('userId');
    var informationId = GetQueryString('informationId');
    var token = GetQueryString('token');
    var version = GetQueryString('version');
    var phoneModel = GetQueryString('phoneModel');
    var systemVersion = GetQueryString('systemVersion');
    var phoneType = GetQueryString('phoneType');

    var collectionStatus,collectionsum,icon_send = 0;

    // 字体大小:0.24,0.26,0.28,0.30,0.32,0.34
	var num=30;

	// 字体变大
	$('.word-intro .big').click(function(){
		num+=3;
		if(num>=39)
		{
			num=39;
		}
		$('.para').css('font-size',(num/100)+'rem');
		$('.para').css('line-height',(num/100)+0.1+'rem');
	});

	// 字体缩小
	$('.word-intro .small').click(function(){
		num-=3;
		if(num<=24)
		{
			num=24;
		}
		$('.para').css('font-size',(num/100)+'rem');
        $('.para').css('line-height',(num/100)+0.14+'rem');
	});

    // 一跳进这个资讯的详情页...先判断是游客还是会员...不管是什么都要展示数据
    if(token == 'f47ae89213514fa79dad5107662e9c24'){//是游客

        getZixunContent(informationId,'');
        // getZixunContent(17,'');



    }else {//是会员

        // getZixunContent(17,88);
        getZixunContent(informationId,userId);

    };

    // 掉ajax接口中的数据...
    function getZixunContent(informationId,userId) {

        $.ajax({
            async: false,
            type: 'post',
            url: getinformationdetail,
            dataType: 'json',
            data:{
                informationId:informationId,
                userId:userId,
                token:token,
                version:version,
                phoneModel:phoneModel,
                systemVersion:systemVersion,
                phoneType:phoneType
            },
            success: function (data) {
                if(data.resultCode==200) {

                    collectionStatus = data.value.collectionStatus;//收藏状态
                    collectionsum = data.value.collectionsum;//收藏数量

                    $('.head-img img').attr( 'src',address + data.value.coverUrl );
                    $('.img-intro').html( data.value.title );
                    $('span.hour').html( data.value.publishTime );
                    $('p.para').html( data.value.content );


                    // 初始化收藏的小Icon...
                    if( collectionStatus == 1 ){//未收藏

                        $('.clct-icon img').attr('src','images/collect_low.svg')

                    }else{//已收藏

                        $('.clct-icon img').attr('src','images/collect_h.svg')

                    };

                    //展示收藏数量...
                    if(data.value.collectionsum>999) {

                        $('span.quality').html( 999 + '<sup>+</sup>' );

                    }else{

                        $('span.quality').html( data.value.collectionsum );

                    };


                };
                console.log('获取资讯内容成功...')
            },
            error: function () {

                console.log('获取资讯内容失败...')

            }
        });



    };

    // 初始状态...
    var type = collectionStatus;
    // 点击收藏...掉后台接口...根据初始状态而确定....
    $('.clct-icon img').click(function () {

        // 首先判断是会员还是游客
        if(token == 'f47ae89213514fa79dad5107662e9c24'){//是游客
            var test2={
                subjectImp1:function(){
                    SubjectJavaScriptImpl.loginOUT('never_have_bug');
                }
            };
            test2.subjectImp1();
        }else{//是会员

            // 初始化收藏的小Icon...
            if( type == 1 ){//未收藏

                $('.clct-icon img').attr('src','images/collect_h.svg');
                type = 0;

                // 向后台发送状态...
                getIconStatus( informationId,userId,type );

                if(icon_send ==1){

                    collectionsum = collectionsum + 1;
                    //展示收藏数量...
                    if(collectionsum>999) {

                        $('span.quality').html( 999 + '<sup>+</sup>' );

                    }else{

                        $('span.quality').html( collectionsum );

                    };

                };

            }else{//已收藏

                $('.clct-icon img').attr('src','images/collect_low.svg');
                type = 1;

                // 向后台发送状态...
                getIconStatus( informationId,userId,type );

                if(icon_send ==1){

                    collectionsum = collectionsum - 1;
                    //展示收藏数量...
                    if(collectionsum>999) {

                        $('span.quality').html( 999 + '<sup>+</sup>' );

                    }else{

                        $('span.quality').html( collectionsum );

                    };

                };

            };

        };


    });

    // 页面初始化...获取收藏Icon的初始状态...
    function getIconStatus( informationId,userId,type ) {

        $.ajax({
            async: false,
            type: 'post',
            url: collectionorcancelinformation,
            dataType: 'json',
            data:{
                informationId:informationId,
                userId:userId,
                type:type,
                token:token,
                version:version,
                phoneModel:phoneModel,
                systemVersion:systemVersion,
                phoneType:phoneType

            },
            success: function (data) {
                if(data.resultCode==200) {

                    //发送接口数据成功...
                    icon_send = 1;

                }else{

                    // 发送接口数据失败...
                    icon_send = 0;

                };
                console.log('收藏状态成功...')
            },
            error: function () {

                console.log('收藏状态失败...')

            }
        });

    };





});
